package org.cgs.web.beans;

import javax.mail.MessagingException;

import org.cgs.web.common.Utility;
 
public class ErrorHelperBean extends HelperBean
{
	private String error;
	private Throwable exception;
	private String user;
	private String email;
	private String summary;
	
	public String getSummary()
	{
		return summary;
	}
	
	public String getEmail()
	{
		return email;
	}
	
	public String getUser()
	{
		return user;
	}
	
	public String getError()
	{
		return error;
	}
	
	public Throwable getException()
	{
		return exception;
	}
	
	public void setSummary(String s)
	{
		summary = s;
	}
	
	public void setUser(String u)
	{
		user = u;
	}
	
	public void setEmail(String e)
	{
		email = e;
	}
	
	public void setError(String e)
	{
		error = e;
	}
	

	public void setException(Throwable e)
	{
		exception = e;
	}
	
	public void sendEmail() throws MessagingException
	{
		String host = "smtp.gmail.com";
		String fromEmail = email;
		String[] recipients = new String[] {"jeffrey.s.garrett@gmail.com"};
		String subject = "CGS Error";
		String message = summary;		
	
		StringBuilder e = new StringBuilder();
		for(int i=0; i<exception.getStackTrace().length; i++)
		{
			e.append(exception.getStackTrace()[i].toString());
		}
		
		message += e.toString();
	
		Utility.sendEmail(host, fromEmail, recipients, subject, message);
	}
}
